// define(function (require) {

var React = require('react');
var antd = require('antd')
var { Select } = antd
var Component = React.Component

const Option = Select.Option;

class Control extends Component {

  constructor(props) {
    super()
    this.state = {
      value: props.value
    }
  }

  handleChange(value) {
    this.props.onChange(value)

    this.setState({ value })
  }

  componentWillReceiveProps(nextProps) {
    if (nextProps.value !== this.state.value) {
      this.setState({
        value: nextProps.value
      })
    }
  }

  render() {
    let { options, placeholder } = this.props
    return (
      <Select {...this.props}
        value={this.state.value}
        placeholder={placeholder}
        onChange={this.handleChange.bind(this)}>
        {
          options.map((option, index) => {
            return (
              <Option key={index} {...option} value={'' + option.value} disabled={option.disabled}>
                {option.label}
              </Option>
            )
          })
        }
      </Select>
    )
  }
}

module.exports = Control


// })